<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
require_once('Core.php');

class Block_Decorator extends Block_Core {

	protected $_component = null;
	
	public function attach($comp) {
		$this->_component = $comp;
		foreach($this->_childs as $key => $val)
			$val->attach($comp->getChild($key));
		return $this;
	}
	
	public function __call($name, $arguments) {
		if ($this->_component) {
            return $this->_component->$name($arguments);
		} else {
			return null;
		}
	}

	public function getTemplate() {
		$res = '';
		if ($this->_template=='') {
			if ($this->_component)
				$res = $this->_component->getTemplate();
		} else {
			$res = $this->_template;
		}
		return $res;
	}
	
	public function getChild($name) {
		$res = null;
		if (!array_key_exists($name, $this->_childs)) {
			if ($this->_component)
				$res = $this->_component->getChild($name);
		} else {
			$res = $this->_childs[$name];
		}
		return $res;
	}

}

/* End of file Decorator.php */